var t = {}, e = getApp(), a = e.globalData.haozuBase;

Page({
    data: {
        keyword: "",
        domain: "bj",
        showSorry: !1,
        seachFlag: !1,
        seachList: [],
        historyList: [],
        commonList: [],
        searchtype: "",
        stype: "",
        kw: ""
    },
    ceshi: function(t) {
        return t;
    },
    inputFun: function(t) {
        var e = this, a = t.detail.value.trim();
        a.length > 0 ? (e.setData({
            seachFlag: !0
        }), n(a, e.data.domain).then(function(t) {
            var r = t.data.building || [];
            e.setData({
                keyword: a,
                showSorry: 0 === r.length,
                seachList: r
            });
        })) : e.setData({
            keyword: a,
            seachFlag: !1,
            showSorry: !1
        });
    },
    recentSearch: function(t) {
        console.log(t);
        var e = this, a = t.currentTarget.dataset.val, r = t.currentTarget.dataset.sid || "", s = t.currentTarget.dataset.stype || "", n = e.data.keyword;
        i(a, r, s), e.setData({
            stype: s,
            kw: n
        }), "listhouse" == e.options.listtype || "index" == e.options.listtype ? wx.navigateTo({
            url: "/pages/list/list_house?keyword=" + t.currentTarget.dataset.val + "&searchInfo=" + t.currentTarget.dataset.searchinfo
        }) : "space" == e.options.listtype ? wx.navigateTo({
            url: "/pages/list/list_space?keyword=" + t.currentTarget.dataset.val + "&searchInfo=" + t.currentTarget.dataset.searchinfo
        }) : wx.navigateTo({
            url: "/pages/list/list?keyword=" + t.currentTarget.dataset.val + "&searchInfo=" + t.currentTarget.dataset.searchinfo
        });
    },
    goSearch: function(t) {
        console.log(t);
        var e = this;
        console.log(e);
        var a = t.detail.value.trim();
        if (0 === a.length) return !1;
        var r = e.data.stype, s = e.data.kw;
        i(a, r, s, ""), "listhouse" == e.options.listtype || "index" == e.options.listtype ? wx.navigateTo({
            url: "/pages/list/list_house?keyword=" + a + "&type=" + r + "&searchInfo=" + t.detail.value
        }) : "space" == e.options.listtype ? wx.navigateTo({
            url: "/pages/list/list_space?keyword=" + a + "&type=" + r + "&searchInfo=" + t.detail.value
        }) : wx.navigateTo({
            url: "/pages/list/list?keyword=" + a + "&type=" + r + "&searchInfo=" + t.detail.value
        });
    },
    searchList: function(t) {
        var e = this, a = t.currentTarget.dataset.val, r = t.currentTarget.dataset.sid || "", s = t.currentTarget.dataset.stype || "", n = e.data.keyword;
        i(a, r, s), e.setData({
            stype: s,
            kw: n
        }), "listhouse" == e.options.listtype || "index" == e.options.listtype ? wx.navigateTo({
            url: "/pages/list/list_house?keyword=" + t.currentTarget.dataset.keyword + "&type=" + t.currentTarget.dataset.stype + "&point_id=" + t.currentTarget.dataset.point_id + "&searchInfo=" + t.currentTarget.dataset.keyword
        }) : "space" == e.options.listtype ? wx.navigateTo({
            url: "/pages/list/list_space?keyword=" + t.currentTarget.dataset.keyword + "&type=" + t.currentTarget.dataset.stype + "&building_id=" + t.currentTarget.dataset.building_id + "&searchInfo=" + t.currentTarget.dataset.keyword
        }) : wx.navigateTo({
            url: "/pages/list/list?building_id=" + t.currentTarget.dataset.building_id + "&point_id=" + t.currentTarget.dataset.point_id + "&searchInfo=" + t.currentTarget.dataset.val
        });
    },
    setOne: function(t) {
        var e = {}, a = t.target.dataset;
        e[a.key] = "true" === a.val, this.setData(e);
    },
    callPhone: function() {
        wx.makePhoneCall({
            phoneNumber: e.globalData["tel-phone"]
        });
    },
    saveLocal: function(t) {
        var e = this;
        console.log(t);
        var a = t.currentTarget.dataset.val, r = t.currentTarget.dataset.sid || "", s = t.currentTarget.dataset.stype || "", n = e.data.keyword;
        return i(a, r, s), e.setData({
            stype: s,
            kw: n
        }), "listhouse" == e.options.listtype || "index" == e.options.listtype ? wx.navigateTo({
            url: "/pages/list/list_house?keyword=" + t.currentTarget.dataset.val + "&searchInfo=" + t.currentTarget.dataset.findinfo
        }) : "space" == e.options.listtype ? wx.navigateTo({
            url: "/pages/list/list_space?keyword=" + t.currentTarget.dataset.val + "&searchInfo=" + t.currentTarget.dataset.findinfo
        }) : wx.navigateTo({
            url: "/pages/list/list?keyword=" + t.currentTarget.dataset.val + "&searchInfo=" + t.currentTarget.dataset.findinfo
        }), !1;
    },
    deleLocal: function() {
        for (var t = this.data.historyList, e = 0; e < t.length; e++) {
            var a = t[e];
            o(decodeURIComponent(a.p), a.k);
        }
        var r = c();
        this.setData({
            historyList: r
        });
    },
    onLoad: function(t) {
        var r = this, s = e.getSecret();
        t.listtype;
        r.setData({
            domain: e.globalData.domain,
            searchtype: t.listtype || ""
        }), wx.request({
            url: a + "/api/miniapps/keyword/",
            data: {
                domain: e.globalData.domain,
                currtime: s.currtime,
                sign: s.sign
            },
            success: function(t) {
                r.setData({
                    commonList: t.data.data
                }), console.log(r.data.commonList);
            }
        }), r.setData({
            historyList: c()
        });
    },
    onReady: function() {},
    onShow: function() {
        this.setData({
            historyList: c()
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});

var r = function(e, a) {
    var r = -1;
    void 0 === t[a] && (t[a] = []);
    for (var s = t[a], n = 0; n < s.length; n++) s[n].ns === e && (r = n);
    return r;
}, s = function(t, r) {
    return new Promise(function(s, n) {
        var i = e.getSecret();
        wx.request({
            url: a + "/api/miniapps/suggestion/",
            data: {
                domain: r,
                keyword: t.trim(),
                currtime: i.currtime,
                sign: i.sign
            },
            success: function(t) {
                s(t.data);
            },
            fail: function(t) {
                n(t);
            }
        });
    });
}, n = function(e, a) {
    return new Promise(function(n, i) {
        var o = r(e, a);
        o > -1 ? setTimeout(function() {
            n(JSON.parse(t[a][o].ru));
        }, 100) : s(e, a).then(function(r) {
            t[a].push({
                ns: e,
                ru: JSON.stringify(r)
            }), t[a].length > 100 && t[a].splice(0, 1), n(r);
        });
    });
}, i = function(t, e) {
    var a = encodeURIComponent(t), r = new Date().getTime(), s = wx.getStorageSync("ht");
    "" === s && (s = "[]");
    for (var n = JSON.parse(s); n.length > 30; ) n.shift();
    for (var i = 0; i < n.length; i++) n[i].p === a && n.splice(i, 1);
    return n.push({
        p: a,
        t: r,
        k: e
    }), wx.setStorage({
        key: "ht",
        data: JSON.stringify(n)
    }), !0;
}, o = function(t, e) {
    var a = encodeURIComponent(t), r = wx.getStorageSync("ht");
    "" === r && (r = "[]");
    for (var s = JSON.parse(r), n = 0; n < s.length; n++) s[n].p === a && s[n].k === e && s.splice(n, 1);
    return wx.setStorageSync("ht", JSON.stringify(s)), !0;
}, c = function() {
    var t = [], e = wx.getStorageSync("ht");
    if ("" === e && (e = "[]"), (t = JSON.parse(e)).length > 0) {
        var a = t.length > 5 ? t.length - 5 : 0;
        return t.slice(a, t.length);
    }
    return [];
};